<template>
  <main class="dashboard-container">
    <!-- 顶部标题栏 -->
    <div class="dashboard-header">
      <div class="header-content">
        <div class="title-section">
          <h1 class="dashboard-title">
            <i class="fas fa-industry title-icon"></i>
            <span class="title-main">合肥凯昇自动化部门</span>
            <span class="title-sub">车间生产看板</span>
          </h1>

        </div>
      </div>
    </div>

    <!-- 主看板内容 -->
    <div class="dashboard-main">
      <!-- 项目基础信息卡片 -->
      <div class="info-card project-card">
        <div class="card-header">
          <h3 class="card-title">
            <i class="fas fa-project-diagram"></i>
            项目信息
          </h3>
        </div>
        <div class="card-content">
          <div class="info-grid">
            <div class="info-item">
              <span class="info-label">项目号</span>
              <span class="info-value">{{ displayData.project_number }}</span>
            </div>
            <div class="info-item">
              <span class="info-label">客户名称</span>
              <span class="info-value">{{ displayData.customer_name }}</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 进度可视化卡片 -->
      <div class="chart-card progress-card">
        <div class="card-header">
          <h3 class="card-title">
            <i class="fas fa-chart-pie"></i>
            项目进度
          </h3>
        </div>
        <div class="card-content">
          <v-chart 
            ref="progressChart"
            class="progress-chart" 
            :option="progressChartOption" 
            autoresize
          />
          <div class="progress-info">
            <div class="progress-text">{{ getProgressText() }}</div>
            <div class="progress-percent">{{ displayData.progress }}%</div>
          </div>
        </div>
      </div>

      <!-- 时间轴卡片 -->
      <div class="chart-card timeline-card">
        <div class="card-header">
          <h3 class="card-title">
            <i class="fas fa-clock"></i>
            时间进度
          </h3>
        </div>
        <div class="card-content">
          <v-chart 
            ref="timelineChart"
            class="timeline-chart" 
            :option="timelineChartOption" 
            autoresize
          />
        </div>
      </div>

      <!-- 负责人信息卡片 -->
      <div class="chart-card manager-card">
        <div class="card-header">
          <h3 class="card-title">
            <i class="fas fa-users"></i>
            负责人分布
          </h3>
        </div>
        <div class="card-content">
          <v-chart 
            ref="managerChart"
            class="manager-chart" 
            :option="managerChartOption" 
            autoresize
          />
        </div>
      </div>

      <!-- 状态仪表盘 -->
      <div class="chart-card gauge-card">
        <div class="card-header">
          <h3 class="card-title">
            <i class="fas fa-tachometer-alt"></i>
            项目状态
          </h3>
        </div>
        <div class="card-content">
          <v-chart 
            ref="gaugeChart"
            class="gauge-chart" 
            :option="gaugeChartOption" 
            autoresize
          />
          <div class="status-info">
            <div class="status-text">{{ getProjectStatus() }}</div>
            <div class="remaining-days">剩余 {{ displayData.remaining_days }} 天</div>
          </div>
        </div>
      </div>

      <!-- 详细信息卡片 -->
      <div class="info-card details-card">
        <div class="card-header">
          <h3 class="card-title">
            <i class="fas fa-info-circle"></i>
            详细信息
          </h3>
        </div>
        <div class="card-content">
          <div class="details-grid">
            <div class="detail-item">
              <span class="detail-label">开始时间</span>
              <span class="detail-value">{{ displayData.start_date }}</span>
            </div>
            <div class="detail-item">
              <span class="detail-label">交付日期</span>
              <span class="detail-value">{{ displayData.delivery_date }}</span>
            </div>
            <div class="detail-item">
              <span class="detail-label">电气负责人</span>
              <span class="detail-value">{{ displayData.electrical_manager }}</span>
            </div>
            <div class="detail-item">
              <span class="detail-label">装配负责人</span>
              <span class="detail-value">{{ displayData.assembly_manager }}</span>
            </div>
            <div class="detail-item full-width">
              <span class="detail-label">备注说明</span>
              <span class="detail-value">{{ displayData.remarks }}</span>
            </div>
            <div class="detail-item full-width">
              <span class="detail-label">更新时间</span>
              <span class="detail-value">{{ displayData.update_time }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>



    <!-- 通知提示 -->
    <div
        id="notification"
        class="notification-dialog"
        :class="{ show: notification.visible, 'notification-success': notification.type === 'success', 'notification-error': notification.type === 'error' }"
        v-show="notification.visible"
    >
      <div class="notification-content">
        <i :class="notification.type === 'success' ? 'fas fa-check-circle' : 'fas fa-exclamation-circle'"
           class="notification-icon"></i>
        <span id="notification-message">{{ notification.message }}</span>
      </div>
    </div>


  </main>
</template>

<script setup>
import {ref, reactive, onMounted, onUnmounted, computed, nextTick} from 'vue';
import {useRouter} from 'vue-router';
import VChart from 'vue-echarts';
import * as echarts from 'echarts';

// 注册必要的组件 - 使用正确的组件导入
import {
  PieChart,
  BarChart,
  LineChart,
  GaugeChart
} from 'echarts/charts';

import {
  TooltipComponent,
  LegendComponent,
  GridComponent,
  TitleComponent
} from 'echarts/components';

import {
  CanvasRenderer
} from 'echarts/renderers';

echarts.use([
  PieChart,
  BarChart, 
  LineChart,
  GaugeChart,
  TooltipComponent,
  LegendComponent,
  GridComponent,
  TitleComponent,
  CanvasRenderer
]);

const router = useRouter();

// --- 响应式数据 ---
const formData = reactive({
  address: 'http://118.24.138.196',
  port: 9005,
  project_id: 1  // 默认项目ID
});

const isConnecting = ref(false);
const isTesting = ref(false);
const isRefreshing = ref(false);
const isLoadingProjects = ref(false);
const apiResponse = ref(null);
const showConfigModal = ref(false);
const projectList = ref([]);
const dataRefreshTimer = ref(null);
const isAutoRefreshEnabled = ref(false);

// 图表引用
const progressChart = ref(null);
const timelineChart = ref(null);
const managerChart = ref(null);
const gaugeChart = ref(null);

// 默认显示数据
const defaultData = {
  project_number: "PRJ-2024-001",
  customer_name: "上海汽车集团股份有限公司",
  start_date: "2024-01-15",
  delivery_date: "2024-03-30",
  remaining_days: 45,
  electrical_manager: "张工程师",
  assembly_manager: "李工程师", 
  progress: 75,
  remarks: "项目进展顺利，按计划推进",
  update_time: "2025-01-15 14:25:33"
};

// 用于显示的数据
const displayData = computed(() => {
  if (apiResponse.value) {
    const responseData = apiResponse.value.data && apiResponse.value.data.length > 0 ? apiResponse.value.data[0] : null;
    
    return {
      project_number: responseData?.project_number || "未知项目",
      customer_name: responseData?.customer_name || "未知客户",
      start_date: responseData?.start_date || "-",
      delivery_date: responseData?.delivery_date || "-",
      remaining_days: responseData?.remaining_days || 0,
      electrical_manager: responseData?.electrical_manager || "未分配",
      assembly_manager: responseData?.assembly_manager || "未分配",
      progress: responseData?.progress || 0,
      remarks: responseData?.remarks || "-",
      update_time: responseData?.update_time || "-"
    };
  }
  
  return defaultData;
});

const notification = reactive({
  visible: false,
  message: '',
  type: 'success'
});

// 检查是否可以加载项目列表
const canLoadProjects = computed(() => {
  return formData.address && formData.port;
});

// 进度环形图配置
const progressChartOption = computed(() => ({
  backgroundColor: 'transparent',
  series: [
    {
      name: '项目进度',
      type: 'pie',
      radius: ['60%', '90%'],
      center: ['50%', '50%'],
      startAngle: 90,
      data: [
        {
          value: displayData.value.progress,
          name: '已完成',
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#00D4FF' },
              { offset: 1, color: '#090979' }
            ])
          }
        },
        {
          value: 100 - displayData.value.progress,
          name: '未完成',
          itemStyle: {
            color: 'rgba(255, 255, 255, 0.1)',
            borderColor: 'rgba(255, 255, 255, 0.2)',
            borderWidth: 2
          },
          label: { show: false },
          labelLine: { show: false }
        }
      ],
      emphasis: {
        scale: false
      },
      label: {
        show: true,
        position: 'center',
        formatter: () => '',
        fontSize: 0
      },
      labelLine: {
        show: false
      },
      animation: true,
      animationType: 'scale',
      animationEasing: 'elasticOut',
      animationDelay: () => Math.random() * 200
    }
  ]
}));

// 时间轴图表配置
const timelineChartOption = computed(() => {
  const startDate = new Date(displayData.value.start_date);
  const deliveryDate = new Date(displayData.value.delivery_date);
  const currentDate = new Date();
  
  const totalDays = Math.ceil((deliveryDate - startDate) / (1000 * 60 * 60 * 24));
  const passedDays = Math.ceil((currentDate - startDate) / (1000 * 60 * 60 * 24));
  
  return {
    backgroundColor: 'transparent',
    grid: {
      left: '5%',
      right: '5%',
      top: '10%',
      bottom: '10%'
    },
    xAxis: {
      type: 'value',
      min: 0,
      max: totalDays,
      axisLine: {
        lineStyle: {
          color: 'rgba(255, 255, 255, 0.3)'
        }
      },
      axisTick: { show: false },
      axisLabel: {
        color: '#ffffff',
        fontSize: 12,
        formatter: (value) => `${Math.round(value)}天`
      },
      splitLine: {
        lineStyle: {
          color: 'rgba(255, 255, 255, 0.1)'
        }
      }
    },
    yAxis: {
      type: 'category',
      data: ['项目时间线'],
      axisLine: { show: false },
      axisTick: { show: false },
      axisLabel: {
        color: '#ffffff',
        fontSize: 14,
        fontWeight: 'bold'
      }
    },
    series: [
      {
        name: '已过去时间',
        type: 'bar',
        stack: 'timeline',
        data: [passedDays],
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
            { offset: 0, color: '#FF6B6B' },
            { offset: 1, color: '#FFE66D' }
          ])
        },
        barWidth: 30,
        animationDelay: 500
      },
      {
        name: '剩余时间',
        type: 'bar',
        stack: 'timeline',
        data: [Math.max(0, displayData.value.remaining_days)],
        itemStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
            { offset: 0, color: '#4ECDC4' },
            { offset: 1, color: '#44A08D' }
          ])
        },
        animationDelay: 800
      }
    ],
    tooltip: {
      trigger: 'axis',
      backgroundColor: 'rgba(0, 0, 0, 0.8)',
      borderColor: '#00D4FF',
      textStyle: {
        color: '#ffffff'
      }
    }
  };
});

// 负责人分布图配置
const managerChartOption = computed(() => ({
  backgroundColor: 'transparent',
  series: [
    {
      name: '负责人分布',
      type: 'pie',
      radius: '70%',
      center: ['50%', '50%'],
      data: [
        {
          value: 1,
          name: `电气: ${displayData.value.electrical_manager}`,
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#667eea' },
              { offset: 1, color: '#764ba2' }
            ])
          }
        },
        {
          value: 1,
          name: `装配: ${displayData.value.assembly_manager}`,
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#f093fb' },
              { offset: 1, color: '#f5576c' }
            ])
          }
        }
      ],
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      },
      label: {
        color: '#ffffff',
        fontSize: 12,
        fontWeight: 'bold'
      },
      labelLine: {
        lineStyle: {
          color: 'rgba(255, 255, 255, 0.5)'
        }
      },
      animationType: 'scale',
      animationEasing: 'elasticOut'
    }
  ],
      tooltip: {
      trigger: 'item',
      backgroundColor: 'rgba(0, 0, 0, 0.8)',
      borderColor: '#00D4FF',
      textStyle: {
        color: '#ffffff'
      }
    }
}));

// 状态仪表盘配置
const gaugeChartOption = computed(() => {
  const urgencyScore = displayData.value.remaining_days <= 7 ? 90 : 
                      displayData.value.remaining_days <= 30 ? 60 : 30;
  
  return {
    backgroundColor: 'transparent',
    series: [
      {
        name: '项目紧急度',
        type: 'gauge',
        center: ['50%', '55%'],
        radius: '80%',
        min: 0,
        max: 100,
        splitNumber: 10,
        axisLine: {
          lineStyle: {
            width: 15,
            color: [
              [0.3, '#4ade80'],
              [0.7, '#fbbf24'],
              [1, '#ef4444']
            ]
          }
        },
        pointer: {
          itemStyle: {
            color: '#00D4FF'
          }
        },
        axisTick: {
          distance: -15,
          length: 8,
          lineStyle: {
            color: '#ffffff',
            width: 2
          }
        },
        splitLine: {
          distance: -15,
          length: 15,
          lineStyle: {
            color: '#ffffff',
            width: 4
          }
        },
        axisLabel: {
          color: '#ffffff',
          distance: 25,
          fontSize: 12
        },
        detail: {
          valueAnimation: true,
          formatter: '{value}',
          color: '#ffffff',
          fontSize: 20,
          fontWeight: 'bold',
          offsetCenter: [0, '70%']
        },
        data: [
          {
            value: urgencyScore,
            name: '紧急度'
          }
        ],
        animationDuration: 2000,
        animationEasing: 'elasticOut'
      }
    ]
  };
});

// 获取进度文本
const getProgressText = () => {
  const progress = displayData.value.progress;
  if (progress >= 90) return '即将完成';
  if (progress >= 70) return '进展良好';
  if (progress >= 50) return '进行中';
  if (progress >= 30) return '需要关注';
  return '进度延迟';
};

// 获取项目状态
const getProjectStatus = () => {
  const progress = displayData.value.progress;
  const remaining = displayData.value.remaining_days;
  
  if (progress >= 100) return '已完成';
  if (remaining <= 0) return '已逾期';
  if (remaining <= 7) return '紧急';
  if (progress >= 70) return '正常';
  return '进行中';
};

// 关闭弹窗
const closeModal = () => {
  showConfigModal.value = false;
};

// 打开配置弹窗
const openConfigModal = () => {
  console.log('⚙️ 配置按钮被点击');
  showConfigModal.value = true;
  if (formData.address && formData.port) {
    loadProjectList();
  }
};

// 启动自动刷新定时器
const startAutoRefresh = () => {
  if (dataRefreshTimer.value) {
    clearInterval(dataRefreshTimer.value);
  }
  
  dataRefreshTimer.value = setInterval(() => {
    if (!isTesting.value && !isRefreshing.value) {
      console.log('自动刷新数据...');
      testInteractionAPI();
    }
  }, 5000);
  
  isAutoRefreshEnabled.value = true;
  console.log('已启动自动刷新，每5秒更新一次数据');
};

// 停止自动刷新定时器
const stopAutoRefresh = () => {
  if (dataRefreshTimer.value) {
    clearInterval(dataRefreshTimer.value);
    dataRefreshTimer.value = null;
  }
  isAutoRefreshEnabled.value = false;
  console.log('已停止自动刷新');
};

// 切换自动刷新
const toggleAutoRefresh = () => {
  console.log('🔄 切换自动刷新按钮被点击');
  if (isAutoRefreshEnabled.value) {
    stopAutoRefresh();
  } else {
    startAutoRefresh();
  }
};

// 获取刷新按钮图标
const getRefreshButtonIcon = () => {
  if (isRefreshing.value) {
    return 'fas fa-spinner fa-spin';
  }
  return isAutoRefreshEnabled.value ? 'fas fa-stop' : 'fas fa-sync-alt';
};

// 获取刷新按钮文本
const getRefreshButtonText = () => {
  if (isRefreshing.value) {
    return '刷新中...';
  }
  return isAutoRefreshEnabled.value ? '停止刷新' : '启动刷新';
};

// 显示通知
const showNotification = (message, type = 'success') => {
  notification.message = message;
  notification.type = type;
  notification.visible = true;
  
  setTimeout(() => {
    notification.visible = false;
  }, 3000);
};

// 保存配置到本地存储
const saveConfig = (address, port, project_id) => {
  try {
    const config = {
      address: address,
      port: port,
      project_id: project_id,
      timestamp: Date.now()
    };
    localStorage.setItem('productionBoardConfig', JSON.stringify(config));
  } catch (error) {
    console.error('保存配置失败:', error);
  }
};

// 从本地存储加载配置
const loadConfig = () => {
  try {
    const config = localStorage.getItem('productionBoardConfig');
    if (config) {
      const parsedConfig = JSON.parse(config);
      formData.address = parsedConfig.address || 'http://118.24.138.196';
      formData.port = parsedConfig.port || 9005;
      formData.project_id = parsedConfig.project_id || 1;
    }
  } catch (error) {
    console.error('加载配置失败:', error);
  }
};

// 仅保存配置
const saveConfigOnly = () => {
  if (!formData.address) {
    showNotification('请输入接口地址', 'error');
    return;
  }

  if (!formData.port) {
    showNotification('请输入端口号', 'error');
    return;
  }

  if (!formData.project_id) {
    showNotification('请选择项目', 'error');
    return;
  }
  
  saveConfig(formData.address, formData.port, formData.project_id);
  showNotification('配置已保存，启动自动刷新!', 'success');
  closeModal();
  startAutoRefresh();
};

// 测试交互接口
const testInteractionAPI = async () => {
  if (!formData.address || !formData.port) {
    showNotification('请先配置接口地址和端口', 'error');
    return;
  }

  isTesting.value = true;

  try {
    const baseUrl = formData.address.includes('://') 
      ? formData.address 
      : `http://${formData.address}`;
    const apiUrl = `${baseUrl}:${formData.port}/api/production/project?project_id=${formData.project_id}`;
    
    console.log('正在调用接口:', apiUrl);
    
    const response = await fetch(apiUrl, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
      signal: AbortSignal.timeout(10000)
    });

    if (response.ok) {
      const data = await response.json();
      console.log('接口响应原始数据:', data);
      
      apiResponse.value = data;
      console.log('✅ API调用成功，已切换到API数据模式');
      
      if (data.data && data.data.length > 0 && data.data[0]) {
        console.log('解析到的项目数据:', data.data[0]);
        
        const projectNumber = data.data[0].project_number || '未知项目';
        const customerName = data.data[0].customer_name || '未知客户';
        console.log(`数据更新成功！项目: ${projectNumber} - 客户: ${customerName}`);
        
        const projectData = data.data[0];
        const progress = projectData.progress || 0;
        const remaining = projectData.remaining_days || 0;
        console.log(`项目进度: ${progress}%, 剩余天数: ${remaining}天`);
        
        // 刷新图表
        await nextTick(() => {
          refreshCharts();
        });
      } else {
        console.warn('API响应中没有有效的项目数据');
        showNotification('接口返回数据格式异常', 'error');
      }
      
    } else {
      throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    }
  } catch (error) {
    console.error('接口调用失败:', error);
    apiResponse.value = null;
    console.log('⚠️ API调用失败，已切换回默认数据模式');
    if (error.name === 'TimeoutError') {
      showNotification('接口调用超时，显示默认数据', 'error');
    } else if (error.name === 'TypeError') {
      showNotification('网络连接失败，显示默认数据', 'error');
    } else {
      showNotification(`接口调用失败: ${error.message}`, 'error');
    }
  } finally {
    isTesting.value = false;
  }
};

// 获取项目列表
const loadProjectList = async () => {
  if (!formData.address || !formData.port) {
    showNotification('请先配置接口地址和端口', 'error');
    return;
  }

  isLoadingProjects.value = true;

  try {
    const baseUrl = formData.address.includes('://') 
      ? formData.address 
      : `http://${formData.address}`;
    const apiUrl = `${baseUrl}:${formData.port}/api/production/projects?index=1&size=50`;
    
    console.log('正在加载项目列表:', apiUrl);
    
    const response = await fetch(apiUrl, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
      signal: AbortSignal.timeout(10000)
    });

    if (response.ok) {
      const data = await response.json();
      console.log('项目列表响应:', data);
      
      if (data.data && Array.isArray(data.data)) {
        projectList.value = data.data;
        console.log(`成功加载 ${data.data.length} 个项目`);
        
        if (projectList.value.length > 0) {
          const defaultProject = projectList.value.find(project => project.default === true);
          if (defaultProject) {
            formData.project_id = defaultProject.project_id;
            console.log(`自动选择默认项目: ${defaultProject.project_number}`);
          } else {
            const currentProjectExists = projectList.value.some(project => project.project_id === formData.project_id);
            if (!currentProjectExists) {
              formData.project_id = projectList.value[0].project_id;
              console.log(`选择第一个项目: ${projectList.value[0].project_number}`);
            }
          }
        }
      } else {
        console.warn('项目列表数据格式异常:', data);
        showNotification('项目列表数据格式异常', 'error');
      }
      
    } else {
      throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    }
  } catch (error) {
    console.error('加载项目列表失败:', error);
    if (error.name === 'TimeoutError') {
      showNotification('加载项目列表超时', 'error');
    } else if (error.name === 'TypeError') {
      showNotification('网络连接失败，无法加载项目列表', 'error');
    } else {
      showNotification(`加载项目列表失败: ${error.message}`, 'error');
    }
  } finally {
    isLoadingProjects.value = false;
  }
};

// 刷新所有图表
const refreshCharts = () => {
  try {
    if (progressChart.value) {
      progressChart.value.setOption(progressChartOption.value, true);
    }
    if (timelineChart.value) {
      timelineChart.value.setOption(timelineChartOption.value, true);
    }
    if (managerChart.value) {
      managerChart.value.setOption(managerChartOption.value, true);
    }
    if (gaugeChart.value) {
      gaugeChart.value.setOption(gaugeChartOption.value, true);
    }
  } catch (error) {
    console.error('刷新图表失败:', error);
  }
};

// --- 生命周期钩子 ---
onMounted(() => {
  console.log('🎨 炫酷车间生产看板已加载');
  localStorage.removeItem('productionBoardConfig');
  loadConfig();
  testInteractionAPI();
  
  // 监听窗口大小变化
  window.addEventListener('resize', refreshCharts);
  
  // 确保按钮可见性
  console.log('✅ 刷新按钮和配置按钮已初始化');
});

onUnmounted(() => {
  stopAutoRefresh();
  window.removeEventListener('resize', refreshCharts);
});
</script>

<style scoped>
/* 全局样式 */
* {
  box-sizing: border-box;
}

.dashboard-container {
  width: 100vw;
  height: 100vh;
  background: #000000;
  color: #ffffff !important;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  position: relative;
}

/* 全局文字颜色设置 */
.dashboard-container *, * {
  color: #ffffff !important;
}

/* 蓝色高亮元素 */
.info-value, .detail-value, .status-text, .progress-percent {
  color: #00D4FF !important;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 1) !important;
  font-weight: 800 !important;
}

/* 普通白色文字 */
.info-label, .detail-label, .progress-text, .remaining-days, 
.card-title, .dashboard-title, .title-main, .title-sub {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 1) !important;
  font-weight: 700 !important;
}

/* 移除背景渐变以增强对比度 */
.dashboard-container::before {
  display: none;
}

/* 头部样式 */
.dashboard-header {
  position: relative;
  z-index: 100;
  background: #000000;
  padding: 1.5rem 2rem;
  box-shadow: 0 4px 20px rgba(0, 212, 255, 0.3);
  color: #ffffff !important;
  overflow: hidden;
}

/* 头部动态边框 */
.dashboard-header::before {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(
    90deg,
    #00D4FF 0%,
    #FF0099 25%,
    #00FF88 50%,
    #FFD700 75%,
    #00D4FF 100%
  );
  background-size: 200% 100%;
  animation: shimmer 5s linear infinite;
}

.header-content {
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 1600px;
  margin: 0 auto;
  flex-wrap: wrap;
  gap: 1rem;
}

.title-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dashboard-title {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 2.5rem;
  margin: 0;
}

/* 保持标题为白色，确保可见性 */
.dashboard-title {
  color: #ffffff !important;
}

.title-main {
  font-size: 2.2rem;
}

.title-sub {
  font-size: 1.8rem;
  opacity: 1;
}



.title-icon {
  background: linear-gradient(45deg, #00D4FF, #FF0099);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 2rem;
}

.data-source-indicator {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  margin-left: 1rem;
  border: 1px solid;
  animation: pulse 2s infinite;
}



/* 主看板区域 */
.dashboard-main {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 2rem;
  padding: 1rem 1.5rem;
  height: calc(100vh - 120px);
  max-width: 1600px;
  margin: 0 auto;
}

/* 卡片基础样式 */
.info-card,
.chart-card {
  background: #333333;
  border-radius: 20px;
  overflow: hidden;
  position: relative;
  transition: all 0.3s ease;
  animation: fadeInUp 0.6s ease forwards;
  color: #ffffff !important;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
}

/* 动态旋转边框效果 */
.info-card::before,
.chart-card::before {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  background: conic-gradient(
    from 0deg,
    #00D4FF 0deg,
    #00D4FF 90deg,
    transparent 92deg,
    transparent 360deg
  );
  border-radius: 23px;
  z-index: -1;
  animation: rotateBorder 8s linear infinite;
}

/* 内部背景遮罩 */
.info-card::after,
.chart-card::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  right: 3px;
  bottom: 3px;
  background: #333333;
  border-radius: 17px;
  z-index: -1;
}

.info-card:hover,
.chart-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border-color: rgba(0, 212, 255, 0.3);
}

.card-header {
  background: #000000;
  padding: 1rem 1.5rem;
  border-bottom: 3px solid #00D4FF;
  color: #ffffff !important;
  position: relative;
  z-index: 1;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 1.5rem;
  margin: 0;
}

/* 保持卡片标题为白色，确保可见性 */
.card-title {
  color: #ffffff !important;
}

.card-content {
  padding: 1.5rem;
  height: calc(100% - 70px);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* 项目信息卡片 */
.project-card {
  grid-column: 1;
  grid-row: 1;
}

.info-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  background: #222222;
  border-radius: 12px;
  border: 2px solid #00D4FF;
  transition: all 0.3s ease;
  color: #ffffff !important;
  margin-bottom: 0.5rem;
}

.info-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.02);
}

.info-label {
  font-size: 1.2rem;
}

.info-value {
  font-size: 1.4rem;
  text-align: right;
}

/* 进度卡片 */
.progress-card {
  grid-column: 2;
  grid-row: 1;
}

.progress-chart {
  width: 100%;
  height: 200px;
  margin-bottom: 1rem;
}

.progress-info {
  text-align: center;
  margin-top: auto;
}

.progress-text {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.progress-percent {
  font-size: 3rem;
}

/* 时间轴卡片 */
.timeline-card {
  grid-column: 3;
  grid-row: 1;
}

.timeline-chart {
  width: 100%;
  height: 100%;
}

/* 负责人卡片 */
.manager-card {
  grid-column: 1;
  grid-row: 2;
}

.manager-chart {
  width: 100%;
  height: 100%;
}

/* 仪表盘卡片 */
.gauge-card {
  grid-column: 2;
  grid-row: 2;
}

.gauge-chart {
  width: 100%;
  height: 200px;
}

.status-info {
  text-align: center;
  margin-top: auto;
}

.status-text {
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
}

.remaining-days {
  font-size: 1.2rem;
}

/* 详细信息卡片 */
.details-card {
  grid-column: 3;
  grid-row: 2;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.3rem;
  height: 100%;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.4rem 0.6rem;
  background: #222222;
  border-radius: 6px;
  transition: all 0.3s ease;
  color: #ffffff !important;
  margin-bottom: 0.1rem;
  position: relative;
  overflow: hidden;
}

/* 详细信息项动态边框 */
.detail-item::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  bottom: -1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    #00D4FF 25%,
    #FF0099 50%,
    #00D4FF 75%,
    transparent 100%
  );
  background-size: 200% 100%;
  border-radius: 7px;
  z-index: -1;
  animation: shimmer 3s linear infinite;
}

.detail-item::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  right: 1px;
  bottom: 1px;
  background: #222222;
  border-radius: 5px;
  z-index: -1;
}

.detail-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.02);
}

.detail-item:hover::before {
  animation: shimmer 1.5s linear infinite;
}

.detail-item.full-width {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
}

.detail-label {
  font-size: 0.85rem;
  min-width: 70px;
  position: relative;
  z-index: 1;
}

.detail-value {
  font-size: 0.9rem;
  text-align: right;
  word-break: break-word;
  position: relative;
  z-index: 1;
}

.detail-item.full-width .detail-value {
  text-align: left;
}

/* 弹窗样式 - 简化版 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: #2a2a2a;
  border: 2px solid #00D4FF;
  border-radius: 20px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: fadeInUp 0.3s ease-out;
}

.modal-header, .modal-body, .modal-footer {
  padding: 1.5rem;
}

.hmi-button {
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  background: #00D4FF;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

.hmi-button:hover {
  background: #0099cc;
  transform: translateY(-2px);
}

/* 通知样式 - 简化版 */
.notification-dialog {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translate(-50%, 0%);
  background: #333333;
  border-radius: 8px;
  padding: 1rem;
  border: 2px solid #00D4FF;
  max-width: 400px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 9999;
}

.notification-dialog.show {
  opacity: 1;
  visibility: visible;
}

.notification-content {
  display: flex;
  align-items: center;
  gap: 1rem;
}



/* 动画效果 */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* 边框旋转动画 */
@keyframes rotateBorder {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 流光动画 */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .dashboard-main {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
  }
  
  .timeline-card {
    grid-column: 1;
    grid-row: 2;
  }
  
  .manager-card {
    grid-column: 2;
    grid-row: 2;
  }
  
  .gauge-card {
    grid-column: 1;
    grid-row: 3;
  }
  
  .details-card {
    grid-column: 2;
    grid-row: 3;
  }
}

@media (max-width: 768px) {
  .dashboard-header {
    padding: 1rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
  }
  
  .title-section {
    text-align: center;
  }
  
  .dashboard-title {
    font-size: 1.4rem;
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .title-main {
    font-size: 1.4rem;
  }
  
  .title-sub {
    font-size: 1.2rem;
  }
  
  .title-indicators {
    justify-content: center;
  }
  
  .header-controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.8rem;
    width: 100%;
  }
  
  .dashboard-main {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(6, 1fr);
    padding: 1rem;
    gap: 1rem;
  }
  
  .project-card,
  .progress-card,
  .timeline-card,
  .manager-card,
  .gauge-card,
  .details-card {
    grid-column: 1;
  }
  
  .project-card { grid-row: 1; }
  .progress-card { grid-row: 2; }
  .timeline-card { grid-row: 3; }
  .manager-card { grid-row: 4; }
  .gauge-card { grid-row: 5; }
  .details-card { grid-row: 6; }
  
  .modal-content {
    width: 95%;
    margin: 1rem;
  }
  
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 1.5rem;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .hmi-button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .title-main { font-size: 1.1rem; }
  .title-sub { font-size: 1rem; }
  .dashboard-title { font-size: 1rem; text-align: center; flex-direction: column; }
  .card-header { padding: 0.8rem 1rem; }
  .card-content { padding: 1rem; }
  .card-title { font-size: 1rem; }
  .progress-chart, .timeline-chart, .manager-chart, .gauge-chart { height: 150px; }
}
</style>
